import * as types from "./mutation-types";
import Api from "api/api";

const state = {
  registerList: {},
  currentRegister: {},
  searchRegisterCondition: {
    pageSize: 10,
    name: "",
    userType: "",
    phone: "",
    departId: ""
  }
};

const getters = {
  registerList: state => state.registerList,
  currentRegister: state => state.currentRegister,
  searchRegisterCondition: state => state.searchRegisterCondition
};

const actions = {
  getRegisterPageS({ commit }, param) {
    return Api.getRegisterPage(param).then(ret => {
      commit(types.UPDATE_REGISTER_LIST, ret.data.data);
      return ret;
    });
  },

  checkRegisterUserS({ commit }, param) {
    return Api.checkRegisterUser(param).then(ret => {
      return ret;
    });
  },
  checkProNumS({ commit }, param) {
    return Api.checkProNum(param).then(ret => {
      return ret;
    });
  }
};

const mutations = {
  [types.UPDATE_REGISTER_LIST](state, payload) {
    state.registerList = payload;
  }
};

export default {
  state,
  getters,
  actions,
  mutations
};
